package oneD.fem.algorithm;

import inf.jlinalg.Vector2D;

/**
 * this class facilitate the geometry of an 2D extended line of implicit
 * equation ax+by+c=0
 * 
 * @author Giang Bui
 * 
 */
public class XLine {

	private double a_;
	private double b_;
	private double c_;

	public double getA() {
		return a_;
	}

	public double getB() {
		return b_;
	}

	public double getC() {
		return c_;
	}

	public XLine(double a, double b, double x0, double y0) {
		a_ = a;
		b_ = b;
		c_ = -a * x0 - b * y0;
	}

	public XLine(Vector2D n1, Vector2D n2) {
		a_ = n2.getX2() - n1.getX2();
		b_ = n1.getX1() - n2.getX1();
		c_ = -n1.getX1() * (n2.getX2() - n1.getX2()) + n1.getX2()
				* (n2.getX1() - n1.getX1());
	}

	/**
	 * 
	 * @param d
	 * @return the intersection of this xline and xline called d
	 */
	public double[] getIntersection(XLine d) {
		double a1 = d.getA();
		double b1 = d.getB();
		double c1 = d.getC();
		return MyLinalg.solve2x2(a_, b_, -c_, a1, b1, -c1);
	}
}
